package ${serviceImplPackageName};

import ${daoPackageName}.${domain.className}Dao;
import ${domianPackageName}.${domain.className};
import ${servicePackageName}.${domain.className}Service;
import com.platform.common.domain.exception.CustomException;
import com.platform.common.domain.to.PageTo;
import com.platform.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* ${(domain.comment)!} service接口实现
*
* @author: ${domain.author}
* @version: 1.0
* @datetime: ${domain.datetime}
*/
@Service
@Slf4j
public class ${domain.className}ServiceImpl implements ${domain.className}Service {

    @Autowired
    private ${domain.className}Dao ${domain.lowerStartClassName}Dao;

    @Override
    public void save(${domain.className} ${domain.lowerStartClassName}) throws Exception {
        ${domain.lowerStartClassName}Dao.save(${domain.lowerStartClassName});
    }

    @Override
    public List<${domain.className}> find(${domain.className} ${domain.lowerStartClassName}) throws Exception {
        return ${domain.lowerStartClassName}Dao.find(${domain.lowerStartClassName});
    }

    @Override
    public PageInfo<${domain.className}> findPage(${domain.className} ${domain.lowerStartClassName}, PageTo page) throws Exception {
        return ${domain.lowerStartClassName}Dao.findPage(${domain.lowerStartClassName}, page);
    }

    @Override
    public void remove(${domain.className} ${domain.lowerStartClassName}) throws Exception {
        if(StringUtils.isBlank(${domain.lowerStartClassName}.getIds())){
            throw new CustomException("主键ids不能为空");
        }
        ${domain.lowerStartClassName}Dao.remove(${domain.lowerStartClassName});
    }

    @Override
    public void remove(String ${domain.lowerStartClassName}Id) throws Exception {
        if(StringUtils.isBlank(${domain.lowerStartClassName}Id)){
            throw new CustomException("主键id不能为空");
        }
        ${domain.lowerStartClassName}Dao.remove(${domain.lowerStartClassName}Id);
    }

    @Override
    public void modify(${domain.className} ${domain.lowerStartClassName}) throws Exception {
    <#list domain.keys as item>
        if(StringUtils.isBlank(${domain.lowerStartClassName}.get${item.upperStartName}())){
            throw new CustomException("主键id不能为空");
        }
        ${domain.lowerStartClassName}Dao.update(${domain.lowerStartClassName});
    </#list>
    }

    @Override
    public void resort(${domain.className} ${domain.lowerStartClassName}) throws Exception {
        if(StringUtils.isBlank(${domain.lowerStartClassName}.getIds())){
            throw new CustomException("ids不能为空");
        }
        ${domain.lowerStartClassName}Dao.resort(${domain.lowerStartClassName});
    }

    @Override
    public ${domain.className} findById(String ${domain.lowerStartClassName}Id) throws Exception {
        if(StringUtils.isBlank(${domain.lowerStartClassName}Id)){
            throw new CustomException("主键id不能为空");
        }
        ${domain.className} result = ${domain.lowerStartClassName}Dao.findById(${domain.lowerStartClassName}Id);
        if (null == result) {
            throw new CustomException("未查到数据");
        }
        return result;
    }
}

